Skip to content

Add 1174. Immediate Food Delivery II solution#271

Merged
myoshi2891 merged 5 commits into
mainfrom
dev-from-macmini
Feb 16, 2026
Merged

Add 1174. Immediate Food Delivery II solution#271
myoshi2891 merged 5 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

@myoshi2891 myoshi2891 commented Feb 16, 2026

Copy link
Copy Markdown
Owner

10d723b — 初期の4つのビジュアル修正 (HTML + ワークフロー)
ef7c383 — MD031準拠 + ゼロ除算対策 (ワークフロー + postgre.md)
9456f54 — 矢印の位置調整 + 数値リテラルの一貫性 (HTML + postgre.md)

  1. MD031 マークダウンリント修正 — svg_flowchart_guidelines.md のコードブロック前後に空行を追加

  2. ゼロ除算対策 — Immediate_Food_Delivery_II_postgre.md の  ソリューションに  と  を追加し、 が空の場合でも  を返すように修正

    DISTINCT ON
    
    NULLIF(COUNT(*), 0)
    
    COALESCE(..., 0.00)
    
    first_orders
    
    0.00
    

pandas: ゼロ除算のガード追加、副作用(DataFrame変異)の防止、重複除去処理の追加。
postgre: 集計結果が空の場合に対応するための COALESCE 追加。

@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

顧客の最初の注文に対し「即座配送」割合を求めるPandas版とPostgreSQL版の解説ドキュメントを追加し、SVGフローチャートと可視化のガイドライン文書も新規追加しました。

Changes

Cohort / File(s) Summary
LeetCode: Immediate Food Delivery ドキュメント
SQL/Leetcode/Intermediate Join/1174. Immediate Food Delivery II/Claude Sonnet 4.5 Extended/Immediate_Food_Delivery_II_pandas.md, SQL/Leetcode/Intermediate Join/1174. Immediate Food Delivery II/Claude Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md
Pandas版とPostgreSQL版の新規ドキュメントを追加。Pandasでは公開署名 immediate_food_delivery(delivery: pd.DataFrame) -> pd.DataFrame と3実装案(idxmin/rank/transform)、NULL処理、エッジケース、計算量、Mermaid図、実行例を収録。PostgreSQL版はCTE+ウィンドウ関数の単一クエリ例および代替(AVG+FILTER、DISTINCT ON)、説明、実行例を追加。
Agent ワークフロー: SVG ガイドライン
.agent/workflows/svg_flowchart_guidelines.md
SVGフローチャート/可視化のベストプラクティス文書を追加(矢印マーカー、viewBox/高さ計算、テキスト重なり回避、Prism.js用CSS上書き例、数値/式例を含む)。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 新しい頁にぴょんと跳ねて
先頭注文をこっそり確かめたよ
Pandasで数えて、SQLで照らして
図とCSSもぴかり✨
配送割合、いっしょに祝おうね

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、追加されたLeetcode問題1174の解決策に関連しており、変更セット全体を適切に要約しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description check ✅ Passed プルリクエストの説明は、変更内容(MD031修正、ゼロ除算対策、DataFrameミューテーション防止)に関連しており、具体的な技術的詳細が含まれています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_pandas.md:
- Around line 92-96: The current selection of first_orders using a min-based
filter can include multiple rows per customer when a customer has tied minimal
order_date; instead, ensure only one "first" order per customer is counted by
switching to the idxmin() approach (use the index of the per-customer minimum
order_date to select a single row) or by deduping the resulting first_orders
with drop_duplicates(subset=['customer_id', 'order_date']) before computing
is_immediate; update the logic around first_orders and the subsequent
is_immediate/percentage computation to reference the single-row-per-customer
result (look for first_orders, transform('min'), idxmin(), and is_immediate in
the diff).
- Line 51: The calculation for percentage can divide by zero when
len(is_immediate) == 0; update the logic around the percentage assignment
(variable percentage) to guard against an empty series/DataFrame (is_immediate)
by checking is_immediate.empty (or len(is_immediate) == 0) and setting
percentage to a safe value (e.g., 0.0 or float('nan')) otherwise perform the
existing calculation rounded to 2 decimals; modify the block that computes
percentage to include this conditional guard referencing percentage and
is_immediate.
- Line 66: The code mutates the input DataFrame by assigning delivery['rn']
which causes side effects; instead compute the rank without modifying the
original by either operating on a copy of delivery or using DataFrame.assign to
produce a new DataFrame (e.g., create a new variable from
delivery.assign(rn=...) and then filter where rn == 1), referencing the same
grouping by 'customer_id' and ranking on 'order_date' so all logic
(groupby('customer_id')['order_date'].rank(method='first', ascending=True))
remains but never writes back into the original delivery object.

In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 63-69: The AVG-based expression can return NULL when first_orders
has no rows, so wrap the aggregation in COALESCE to return 0.0 instead;
specifically update the SELECT that computes immediate_percentage (ROUND(100.0 *
AVG(is_immediate::int), 2) AS immediate_percentage) to use
COALESCE(AVG(is_immediate::int), 0.0) so the query yields 0.00 instead of NULL
for empty result sets.
- Around line 37-44: The query that computes immediate_percentage can return
NULL when the table is empty; update the SELECT that references SUM(CASE...) /
COUNT(*) (the immediate_percentage expression that queries first_orders filtered
by rn = 1) to explicitly handle NULL/zero by wrapping the whole ROUND(...)
expression with COALESCE(..., 0.0) (or otherwise check COUNT(*) = 0) so the
query returns 0.0 instead of NULL for empty result sets.

- Fix Step 3/4 SVG: increase viewBox height and reposition summary
  text below table rows to prevent overlap
- Fix copy button CSS: add !important overrides and broader selectors
  to ensure Prism.js copy-to-clipboard buttons are visible with
  Tailwind CSS preflight reset
- Fix flowchart SVG arrows: reduce marker refX (9->5) so arrowheads
  are not hidden behind nodes, increase viewBox (950->1000),
  reposition merge point and lower nodes for proper spacing
- Add SVG flowchart guidelines workflow for future reference

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @.agent/workflows/svg_flowchart_guidelines.md:
- Around line 19-23: The fenced code block containing "viewBox height =
header_height + (row_count × row_height) + summary_text_spacing + padding"
violates MD031; add a blank line immediately before the opening ``` and a blank
line immediately after the closing ``` so the fence is separated from
surrounding text (update the markdown around that fenced block in
svg_flowchart_guidelines.md).

In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 88-93: Guard against division-by-zero when computing
immediate_percentage: replace the denominator COUNT(*) in the ROUND expression
with NULLIF(COUNT(*), 0) and wrap the whole division with COALESCE(..., 0) so
the query on first_orders returns 0.00 when the table is empty; update the
expression that uses ROUND and COUNT(*) FILTER (WHERE is_immediate) accordingly.

Comment on lines +19 to +23
2. **For dynamic data tables**, calculate viewBox height based on number of rows:
```
viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

フェンス前後の空行が必要です(MD031)。

markdownlint の指摘どおり、フェンスの前後に空行を入れてください。

🧹 修正案
-2. **For dynamic data tables**, calculate viewBox height based on number of rows:
-    ```
-    viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
-    ```
+2. **For dynamic data tables**, calculate viewBox height based on number of rows:
+
+    ```
+    viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
+    ```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
2. **For dynamic data tables**, calculate viewBox height based on number of rows:
```
viewBox height = header_height + (row_count × row_height) + summary_text_spacing + padding
```
2. **For dynamic data tables**, calculate viewBox height based on number of rows:
🧰 Tools
🪛 markdownlint-cli2 (0.20.0)

[warning] 20-20: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

🤖 Prompt for AI Agents
In @.agent/workflows/svg_flowchart_guidelines.md around lines 19 - 23, The
fenced code block containing "viewBox height = header_height + (row_count ×
row_height) + summary_text_spacing + padding" violates MD031; add a blank line
immediately before the opening ``` and a blank line immediately after the
closing ``` so the fence is separated from surrounding text (update the markdown
around that fenced block in svg_flowchart_guidelines.md).

- Fix MD031 markdown linting in svg_flowchart_guidelines.md by adding
  blank lines around fenced code block
- Add NULLIF/COALESCE to postgre.md DISTINCT ON solution to guard
  against division by zero when first_orders is empty, returning 0.00
  instead of NULL or error

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1174. Immediate Food Delivery II/Claude
Sonnet 4.5 Extended/Immediate_Food_Delivery_II_postgre.md:
- Around line 88-96: The COALESCE fallback value is formatted
inconsistently—change the literal in the SELECT that defines
immediate_percentage from 0.00 to 0.0 so numeric-literal formatting matches the
earlier 0.0 usage; update the COALESCE(...) AS immediate_percentage expression
that uses NULLIF(COUNT(*), 0) and COUNT(*) FILTER (WHERE is_immediate) to return
0.0 instead of 0.00.

- Fine-tune flowchart merge point arrows (HTML): adjust horizontal
  endpoints from 440/460 to 435/465 and vertical endpoints from 800/910
  to 795/895 for better visual alignment
- Fix numeric literal consistency (postgre.md): change COALESCE fallback
  from 0.00 to 0.0 to match earlier 100.0 formatting style
@myoshi2891 myoshi2891 merged commit 9839a10 into main Feb 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant